<?php
require_once 'Pipes/Uri.php';

class Pipes_Uri_Parser
{
    public function __construct() {
        
    }
    
    public function parse($uri) {
        $extras = array();
        
        if (substr($uri, 0, 1) == '/') {
            $uri = substr($uri, 1);
        }
        $explodedUri = explode('/', $uri);
        $controller = array_shift($explodedUri);
        
        if (count($explodedUri) > 1) {
            $action = implode('/', $explodedUri);
        }
        else {
            $action = array_shift($explodedUri);
        }
        
        if (($pos = strpos($action, '?')) !== false) {
            $queryString = substr($action, $pos + 1);
            parse_str($queryString, $extras);
            $action = substr($action, 0, $pos);
        }
        
        
        return new Pipes_Uri($controller, $action, $extras);
    }
}

